package com.fita.webpay.entity;

import org.apache.commons.lang3.StringUtils;
import com.demo2do.core.utils.Alias;

/**
 * 
 * @author mohanlan
 *
 */
@Alias("PayType")
public enum PayType {
    
    PC("pc"), // 网页支付（银行卡、支付宝扫码、微信扫码）
    
    WECHAT("wechat"), // 微信网页
    
    ALIPAY("alipay"); // 支付宝生活号
    
private String code;
    
    /**
     *
     * @param code
     */
PayType(String code) {
        this.code = code;
    }

    /**
     * get pay channel by the code
     *
     * @param code
     * @return
     */
    public static PayType codeOf(String code) {
        for(PayType channel : PayType.values()) {
            if(StringUtils.equalsIgnoreCase(channel.getCode(), code)) {
                return channel;
            }
        }
        return null;
    }

    /**
     * whether pay channel supports code
     *
     * @param code
     * @return
     */
    public static boolean supports(String code) {
        return codeOf(code) != null;
    }
    
    public boolean isPc() {
        return StringUtils.equalsIgnoreCase(this.getCode(), "pc");
    }

    /**
     *
     * @return
     */
    public boolean isAlipay() {
        return StringUtils.equalsIgnoreCase(this.getCode(), "alipay");
    }

    /**
     *
     * @return
     */
    public boolean isWechat() {
        return StringUtils.equalsIgnoreCase(this.getCode(), "wechat");
    }

    /**
     * @return the code
     */
    public String getCode() {
        return this.code;
    }

    /**
     *
     * @return
     */
    public String getName() {
        return this.name();
    }

    /**
     *
     * @return
     */
    public int getOrdinal() {
        return this.ordinal();
    }
}
